// 防抖
export const debounce = (func, delay) => {
    let timer;
    return function (...args) {
        clearTimeout(timer);
        timer = setTimeout(() => {
            func.apply(this, args);
        }, delay);
    };
};


export const dataGroup = (arr) => {
    const result = {};
    arr.forEach((item) => {
        for (const key in item) {
            if (item.hasOwnProperty(key)) {
                if (!result[key]) result[key] = [];
                result[key].push(item[key] - 0 == item[key] ? item[key] - 0 : item[key]);
            }
        }
    });
    return result;
};

export const fitChartSize = (size, defalteWidth = 1920) => {
    let clientWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
    if (!clientWidth) return size;
    let scale = (clientWidth / defalteWidth);
    return Number((size * scale).toFixed(3));
}